/*
 * @Author: 肖芬芳 1911683843@qq.com
 * @Date: 2022-10-20 16:33:10
 * @LastEditors: 肖芬芳 1911683843@qq.com
 * @LastEditTime: 2022-11-24 09:36:00
 * @FilePath: \node_study\routes\admin\system\user\add.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { User } = require('../../../model/user.js');
// 对象规则验证
const Joi = require('joi');
// hash密码
const bcrypt = require('bcryptjs');

module.exports = async (req, res) => {
    console.log(req.fields)
    // 生成盐
    const salt = await bcrypt.genSalt(10);
    // 使用盐对密码进行加密
    req.fields.password = await bcrypt.hash(req.fields.password, salt);
    User.create({
        ...req.fields,
        createTime: new Date().getTime(),
    })
        .then(result => console.log(result))
        .catch(err => console.log(err));
    res.send({ 'code': 0, "msg": "新增成功" });
}